
package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.common.util.BeanUtil;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbInfoSubjectEntity;
import com.huatai.manage.entity.TbTrialInfoEntity;
import com.huatai.manage.entity.TbTrialSubjectEntity;
import com.huatai.manage.mapper.TbInfoSubjectMapper;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbInfoSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.manage.service.TbTrialInfoService;
import com.huatai.manage.vo.PageVo;
import com.huatai.manage.vo.TbInfoSubjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 试验对象关联; 服务实现类
 * </p>
 *
 * @author luoxc
 * @since 2023-03-21
 */
@Service
public class TbInfoSubjectServiceImpl extends ServiceImpl<TbInfoSubjectMapper, TbInfoSubjectEntity> implements TbInfoSubjectService {

	@Autowired
	private TbInfoSubjectMapper infoSubjectMapper;

	/**
	 * 根据试验名称和试验对象名称模糊查询试验信息和试验模型对象关系
	 *
	 * @param pageQuery
	 * @return
	 */
	@Override
	public PageVo pageList( PageQuery<TbInfoSubjectEntity> pageQuery) {
		Page<TbInfoSubjectEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		List<TbInfoSubjectVo> tbInfoSubjectVos = infoSubjectMapper.pageList(page, pageQuery.getData());
		PageVo pageVo = BeanUtil.copyProperties(page, PageVo.class);
		pageVo.setRecords(tbInfoSubjectVos);
		return pageVo;
	}

	/**
	 * 根据主键id获取试验信息和试验模型对象关系
	 *
	 * @param id
	 * @return
	 */
	@Override
	public TbInfoSubjectVo getOneById(String id) {
		return infoSubjectMapper.getOneById(id);
	}

	/**
	 * 查询所有数据
	 *
	 * @return
	 */
	@Override
	public List<TbInfoSubjectVo> infoList() {
		return infoSubjectMapper.infoList();
	}

	/**
	 * 修改状态
	 *
	 * @param id
	 * @param state
	 * @return
	 */
	@Override
	public boolean updateState(String id, String state) {
		if (StringUtil.isEmpty(id) || StringUtil.isEmpty(state)) return false;
		LambdaUpdateWrapper<TbInfoSubjectEntity> wrapper = Wrappers.lambdaUpdate();
		wrapper.eq(TbInfoSubjectEntity::getId, id);
		wrapper.set(TbInfoSubjectEntity::getState, state);
		return this.update(wrapper);
	}

	/**
	 * @Description 根据试验id查询对象关联列表
	 * @Date 2023/4/5 14:41
	 * @Param trialId
	 * @return
	 */
	@Override
	public List<TbInfoSubjectVo> getByTrialId(String trialId) {

		return infoSubjectMapper.getByTrialId(trialId);
	}


}
